<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/view/feature/vochManage/vochCommon.php'; ?>
<script>
    function voch_query_callback(ps_data) {
        if("OK" != ps_data["result"]) {
            return com_show_err(ps_data);
        }
        $("#voch_query_report_main").show();
        auto_update_grid("id_voch_query_grid", ps_data);
        $("#id_voch_query_grid")[0].grid.endReq(); //hide the show message
        activatePanel("tabs", "id_tab_title_ivoch_qeury");

        var grid_items_count = ps_data.grid_data.length;
        //console.log("get grid data rows:" + grid_items_count);
        if(0 == grid_items_count) {
            alert("no data.");
        } else {
            $("#id_div_query_condition").dialog("close");
        }
    }

    function do_post_query() {
        var cond_info = $("#id_div_query_condition").acc_get_sql_text();
        call_rpc("voch_query_req", {cond:cond_info}, voch_query_callback);
    }

    $(document).ready(function(){
        voch_query_grid_init();
        $("#id_lnav_vochQeury").click(function() {
            var gridArrayData = [];
            $("#id_voch_query_grid").jqGrid('setGridParam', { data: gridArrayData});
            // hide the show message
            $("#id_voch_query_grid")[0].grid.endReq();
            $("#id_voch_query_grid").trigger('reloadGrid');                        
            activatePanel("tabs", "id_tab_title_ivoch_qeury");
        });
        $("#voch_query_report_main").hide();
        
        var dialog = $("#id_div_query_condition").dialog({
            autoOpen: false,
            height: 400,
            width: 550,
            modal: true,
            buttons: {
                "取消": function() {dialog.dialog( "close" );},
                "查询": do_post_query,
            },
            close: function() {
                //console.log("common close. do something like reset the query condition...");
            },
            open: function() {
                $(this).closest(".ui-dialog")
                    .find(".ui-dialog-titlebar-close")
                    .removeClass("ui-dialog-titlebar-close")
                    .html("<span class='ui-button-icon-primary ui-icon ui-icon-closethick'></span>");
                var div_query_wrapper = $("[aria-describedby='id_div_query_condition']");
                var old_wid = div_query_wrapper.find(".ui-dialog-title").width();
                div_query_wrapper.find(".ui-dialog-title").width(old_wid - 2).css("text-align", "left");
            }
        });
        //$("#id_query_condition_btn").on("click", function() {dialog.dialog( "open" );});
        $("#id_div_query_condition").acc_search({
            model:[
                {label: '流水号', name:'flowNo', search_type:'int', def_comp:'gt'},
                {label: '凭证日期', name:'vochDate', search_type:'date', def_comp:'gt'},
                {label: '凭证日期', name:'vochDate', search_type:'date', def_comp:'lt'},
                {label: '凭证字', name:'zID', search_type:'select', data_src: '<option value="不限" select="selected">不限</option>' + '<?php echo get_voch_zi_option_list();?>'},
                {label: '凭证号', name:'vochNo', search_type:'int'},
                {label: '附件', name:'attachCnt', search_type:'int'},
                {label: '摘要', name:'summary', search_type:'text'},
                {label: '会计科目', name:'accName', search_type:'int'},
                {label: '借方', name:'de', search_type:'int'},
                {label: '贷方', name:'cr', search_type:'int'},
            ],
            height:450,
        });
        $("#id_query_condition_btn").on("click", function() {dialog.dialog( "open" );});
    });
            
    function voch_query_grid_init(){
        $("#id_voch_query_grid").jqGrid({
            colModel: [
                //{label: 'id', name: 'id', width: 50, sorttype: 'integer'},
                {label: '流水号', name: 'flowNo', width: 60, sorttype:'integer', fixed: true},
                {label: '凭证日期', name: 'vochDate', width: 80, fixed: true},
                {label: '凭证字', name: 'Zname', width: 50, fixed: true},
                {label: '凭证号', name: 'vochNo', width: 50, fixed: true},
                
                {label: '摘要', name: 'summary', width: 150, fixed: true},
                {label: '科目代码', name: 'serialNo', width:80, fixed: true},
                {label: '科目名称', name: 'accName', width: 150, fixed: true},
                
                {label: '借方', name: 'de', width: 100, formatter: 'number', align: 'right', sorttype: 'integer', fixed: true},
                {label: '贷方', name: 'cr', width: 100, formatter: 'number', align: 'right', sorttype: 'integer', fixed: true},
                
                {label: '附件', name: 'attachCnt', width: 30, fixed: true},
                {label: '制单', name: 'makerName', width: 60, fixed: true},
                {label: '审核', name: 'reviwerName', width: 60, fixed: true},
                {label: '记账', name: 'bookerName', width: 60, fixed: true},
                {label: '会计主管', name: 'accManagerName', width: 60, fixed: true},
                
                {label: '业务员', name: 'saleManName', width: 60, fixed: true},
                {label: '项目1', name: 'Prj1', width: 100, fixed: true},
                {label: '项目2', name: 'Prj2', width: 100, fixed: true},
                {label: '项目3', name: 'Prj3', width: 100, fixed: true},
                {label: '往来', name: 'auxCurrent', width: 250, fixed: true},
                {label: '结算方式', name: 'accWay', width: 100, fixed: true},
                {label: '结算号', name: 'accCloseNo', width: 80, fixed: true},
                {label: '结算日期', name: 'accCloseDate', width: 80, fixed: true},
                
            ],
            viewrecords: true,
            width: 1010,
            height: 460,
            rowNum: 15,
            datatype: 'local',
            pager: "#id_voch_query_pager",
            cmTemplate: {title: false}, // do not show tooltips on grid
        });
        $("#id_voch_query_grid").jqGrid('navGrid', '#id_voch_query_pager', {edit : false,add : false,del:false});
        //$("#id_voch_query_grid").jqGrid('bindKeys');
        fix_jqgrid_header_and_body_width_bug("id_voch_query_grid");
        
    }
</script>
<div>
    <div class="BtnLeftArrangeFirst" ><button id="id_query_condition_btn" style="height:30px; width:100px;" class="ui-widget ui-button ui-corner-all">设置查询条件</button></div>
    <div class="acc_clear"></div>
    <div id="voch_query_report_main">
        <table id="id_voch_query_grid"></table> 
        <div id="id_voch_query_pager"></div>
    </div>
    <div id="id_div_query_condition" title="查询条件" style="display:none;">
    </div>
</div>